package simultaneously.share;

/**
 * Created by 焕滨 on 2016/3/12.
 */
public class SynchronizedEvenGenerator extends IntGenerator {
    private int currentEvenValue = 0;
    @Override
    //synchronized 关键字表示，多线程调用这个类的这个方法的时候，会加锁
    public synchronized int next() {
        currentEvenValue++;
        Thread.yield();
        currentEvenValue++;
        return currentEvenValue;
    }

    public static void main(String[] args){
        EvenChecker.test(new SynchronizedEvenGenerator());
    }
}
